package com.sky.controller.user;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author lwd
 * @since 2023-04-24
 */
@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-菜品订单接口")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     *
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("submit")
    @ApiOperation("用户下单")
    public Result submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = ordersService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * c端历史订单查询
     * @param page
     * @param pageSize
     * @param status
     * @return
     * zhongweiwei
     */

    @GetMapping ("historyOrders")
    @ApiOperation("c端历史订单查询")
    public Result <PageResult>historyOrders(Integer page ,Integer pageSize ,Integer status) {
        log.info("c端历史订单查询：{} ", status ,page,pageSize);
        PageResult pageResult=ordersService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    /**
     * zhongweiwei
     * c端订单详情查询
     * @param id
     * @return
     */
    @GetMapping ("orderDetail/{id}")
    @ApiOperation("c端订单详情查询")
    public Result <OrderVO>OrderDetail( @PathVariable Long id) {
        log.info("c端订单详情查询：{} ",id );
        OrderVO orderVO=ordersService.detailsOrder(id);
        return Result.success(orderVO);
    }

    /**
     * 取消订单
     * zhongweiwei
     */
    @ApiOperation("取消订单")
    @PutMapping("cancel/{id}")
    public Result CancelOrder(@PathVariable Long id) {
        log.info("取消订单{}", id);
        ordersService.CancelOrders(id);
        return Result.success();

    }

    /**
     * zhongweiwei
     * 再来一单
     * @param id
     * @return
     */
    @ApiOperation("再来一单")
    @PostMapping("repetition/{id}")
    public Result repetitionOrder(@PathVariable Long id) {
        log.info("再来一单{}", id);
        ordersService.repetitionOrder(id);
        return Result.success();

    }
}
